package com.dingding.special.user.vehicle.service.impl;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.common.core.util.paravalidate.ValiResult;
import com.dingding.common.core.util.paravalidate.ValidateUtil;
import com.dingding.special.user.deposit.code.DepositCodeMsg;
import com.dingding.special.user.vehicle.dao.ISpecialVehicleDao;
import com.dingding.special.user.vehicle.dto.ReqSpecialVehicleDTO;
import com.dingding.special.user.vehicle.dto.ResSpecialVehicleDTO;
import com.dingding.special.user.vehicle.service.ISpecialVehicleService;

/**
 * 
 * @ClassName: SpecialVehicleServiceImpl 
 * @Description: 专车车辆Service实体类
 * @author YHQ
 * @date 2016年8月25日 上午10:42:28
 * @since V2.4.0
 * 
 */
@Component("specialVehicleService")
public class SpecialVehicleServiceImpl implements ISpecialVehicleService{

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name="specialVehicleDao")
	private ISpecialVehicleDao specialVehicleDao;
	
	/**
	 * 
	 * @Title: getSpecialVehicleInfo 
	 * @Description: 获取专车车辆信息
	 * @param reqSpecialVehicleDTO 客户端请求Bean
	 * @author YHQ 
	 * @since V2.4.0
	 * @return ResponseEntity<ResSpecialVehicleDTO>    返回类型
	 * 
	 */
	@Override
	public ResponseEntity<ResSpecialVehicleDTO> getSpecialVehicleInfo(ReqSpecialVehicleDTO reqSpecialVehicleDTO) {
		
		ResponseEntity<ResSpecialVehicleDTO> response = new ResponseEntity<ResSpecialVehicleDTO>();
		
		// 判断客户端请求参数是否为空
		boolean flag = validateVehicleInfo(response, reqSpecialVehicleDTO);
		
		if(!flag){
			return response;
		}
		
		ResSpecialVehicleDTO specialVehicle = specialVehicleDao.getVehicleInfo(reqSpecialVehicleDTO.getUserId());
		
		response.setCode(HttpStatus.SC_OK);
		response.setResponseBody(specialVehicle);
		
		return response;
	}

	/**
	 * 
	 * @Title: validateVehicleInfo 
	 * @Description: 验证车辆信息
	 * @param @return    设定文件 
	 * @author YHQ 
	 * @since V2.4.0
	 * @return boolean    返回类型
	 * 
	 */
	public boolean validateVehicleInfo(ResponseEntity<ResSpecialVehicleDTO> response,ReqSpecialVehicleDTO reqSpecialVehicleDTO){
		
		// 判断客户端请求数据是否为空
		ValiResult valiResult = ValidateUtil.validateBeanIsAvaliable(reqSpecialVehicleDTO, ReqSpecialVehicleDTO.class);
		
		if (!valiResult.isAvailable()) {
			response.setCode(HttpStatus.SC_FORBIDDEN);
			response.setErrorMessage(DepositCodeMsg.DATA_NULL_PARAM_MESSAGE);// 客户端请求数据为空
			response.setPromptMessage(DepositCodeMsg.APP_ERROR);// 客户端请求数据为空
			response.setNullProperties(valiResult.getNullFieldName());
			log.error("为空字段为：" + valiResult.getNullFieldName());
			return false;
		}
		
		return true;
	}
	
}
